package com.fm.service.impl;

import com.fm.common.ResultResponse;
import com.fm.dao.PriceMapper;
import com.fm.pojo.Price;
import com.fm.service.IPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("priceService")
public class PriceServiceImpl implements IPriceService{

    @Autowired
    private PriceMapper priceMapper;

    public ResultResponse saveOrUpdatePrice(Price price){
        if(price!=null){
            if (price.getId()!=null){
                int rowCount =priceMapper.updateByPrimaryKey(price);
                if(rowCount > 0){
                    return ResultResponse.isSuccessMessage("更新价目成功");
                }
                return ResultResponse.isErrorMessage("更新价目失败");
            }else {
                int rowCount =priceMapper.insert(price);
                if(rowCount > 0){
                    return ResultResponse.isSuccessMessage("更新价目成功");
                }
                return ResultResponse.isErrorMessage("更新价目失败");
            }
        }
        return ResultResponse.isErrorMessage("新增或更新产品参数不正确");
    }
}
